package svc

import (
	v9 "github.com/redis/go-redis/v9"
	"github.com/zeromicro/go-queue/kq"
	"gorm.io/gorm"
	"mall-backend/core/mysql"
	"mall-backend/core/redis"
	"mall-backend/rpc/goods/internal/config"
)

type ServiceContext struct {
	Config             config.Config
	KqUserPusherClient *kq.Pusher
	DB                 *gorm.DB
	RedisCluster       *v9.ClusterClient
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:             c,
		KqUserPusherClient: kq.NewPusher(c.KqUsersPusherConfig.Brokers, c.KqUsersPusherConfig.Topic),
		DB:                 mysql.InitDatabase(c.DBConfig.Dsn),
		RedisCluster:       redis.NewRedisClusterClient(c.RedisConfig.Addrs, c.RedisConfig.Password),
	}
}
